<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>流水号</title>
        <#include "/pubHeadStyle.html">
    </head>
    <body>
        <form class="layui-form" style="height: 353px;overflow: auto;">
            <div class="layui-btn-container" style="position: fixed;bottom:0;left: 42%;">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="identityForm">保存
                </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger" id="returnIdentityList">取消</button>
            </div>
            <div class="layui-row" style="margin-top: 15px;height: 618px;">
                <div class="layui-form-item item-first"
                     style="border-top:1px solid #ccc;margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label" style="border-right:1px solid #ccc;background: #f2f2f2;">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="identityName" id="identityName" lay-verify="required" maxlength="25"
                               autocompvare="off"
                               placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label" style="border-right:1px solid #ccc;background: #f2f2f2;">别名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="alias" name="alias" lay-verify="required" placeholder="请输入"
                               maxlength="10" autocompvare="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label"
                           style="height: 358px;border-right:1px solid #ccc;background: #f2f2f2;">规则</label>
                    <div class="layui-input-inline">
                        <input type="text" lay-verify="required" placeholder="请输入" name="rule" id="rule"
                               autocompvare="off"
                               value="{yyyy}{MM}{dd}{NO}"
                               class="layui-input">
                        <p>{yyyy}{MM}{dd}{NO}</p>
                        <p>{yyyy}表示年份</p>
                        <p>{MM}表示月份，如果月份小于10，则加零补齐，如1月份表示为01。</p>
                        <p>{mm}表示月份，月份不补齐，如1月份表示为1。</p>
                        <p>{DD}表示日，如果小于10号，则加零补齐，如1号表示为01。</p>
                        <p>{dd}表示日，日期不补齐，如1号表示为1。</p>
                        <p>{NO}表示流水号，前面补零。</p>
                        <p>{no}表示流水号，后面补零。</p>
                        <p>{ORG}表示当前用户所属组织的code代码</p>
                        <p>{UC}表示当前用户所提交的code代码</p>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label"
                           style="height: 77px;border-right:1px solid #ccc;background: #f2f2f2;">生成类型</label>
                    <div class="layui-input-inline" style="width: 500px">
                        <input type="radio" name="genType" lay-filter="genType" value="1" title="每天生成" checked>
                        <input type="radio" name="genType" lay-filter="genType" value="2" title="每月生成">
                        <input type="radio" name="genType" lay-filter="genType" value="3" title="每年生成">
                        <input type="radio" name="genType" lay-filter="genType" value="0" title="递增">
                        <p>流水号生成规则：</p>
                        <p>1.每天生成。每天从初始值开始计数。</p>
                        <p>2.递增，流水号一直增加。</p>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label"
                           style="height: 188px;border-right:1px solid #ccc;background: #f2f2f2;">流水号长度</label>
                    <div class="layui-input-inline">
                        <input type="text" lay-verify="required|number" placeholder="请输入" autocompvare="off" value="5"
                               name="noLength"
                               d="noLength"
                               class="layui-input">
                        <p>这个长度表示当前流水号的长度数，只包括流水号部分{NO},如果长度为5，当前流水号为5，则在流水号前补4个0，表示为00005。</p>
                        <p>{no}如果长度为5，当前流水号为501，则在流水号后面补5个0，表示为50100000，如果长度为1，则流水号一直递增。</p>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label" style="border-right:1px solid #ccc;background: #f2f2f2;">初始值</label>
                    <div class="layui-input-inline">
                        <input type="text" lay-verify="required|number" placeholder="请输入" autocompvare="off" value="1"
                               name="initValue"
                               id="initValue"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label"
                           style="height: 94px;border-right:1px solid #ccc;background: #f2f2f2;">步长</label>
                    <div class="layui-input-inline">
                        <input type="text" lay-verify="required|number" placeholder="请输入" autocompvare="off" value="1"
                               name="step"
                               id="step"
                               class="layui-input">
                        <p>流水号每次递加的数字，默认步长为1。比如步长为2，则每次获取流水号则在原来的基础上加2。</p>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-bottom:0;border-bottom:1px solid #ccc;">
                    <label class="layui-form-label"
                           style="height: 92px;border-right:1px solid #ccc;background: #f2f2f2;">用户编号</label>
                    <div class="layui-input-inline">
                        <input type="text" placeholder="请输入" autocompvare="off" name="userCode"
                               id="userCode"
                               class="layui-input">
                        <p>流水号添加用户编码，默认为空，如果需要添加用户编码还需要在规则中添加相对应的规则代码。</p>
                    </div>
                </div>
            </div>

        </form>
        <script>
            layui.config({
                base: serverPath.formPath + staticPath.formPath //静态资源所在路径
            }).extend({
                index: 'index' //主入口模块
            }).use(['index', 'setter', 'commons', 'form', 'jquery','layer'], function () {
                var form = layui.form, layer = layui.layer, commons = layui.commons;
                var setter = layui.setter;
                var $ = layui.$;
                form.render();
                var index = parent.layer.getFrameIndex(window.name);
                $(document).on('click', '#returnIdentityList', function () {
                    parent.layer.close(index);
                });

                var genType;
                form.on('radio(genType)', function (data) {
                    if ($("input[name='genType']")[0].checked) {
                        genType = $(this).val();
                    }
                    form.render();
                });

                //监听提交
                form.on('submit(identityForm)', function (data) {
                    data.field["genType"] = genType;
                    $.ajax({
                        url: serverPath.workflowPath + setter.workflowLinkPath + "identity/add",
                        type: "POST",
                        contentType: 'application/json',
                        dataType: 'json',
                        data: JSON.stringify(data.field),
                        success: function (result) {
                            if (commons._filterRecord(result)) {
                                window.layer.alert(result.msg, function (index) {
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                                    parent.layui.table.reload('serNumber', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                    parent.layui.totalFilter.init('serNumber');
                                });
                            } else {
                                window.layer.alert(result.msg);
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert("保存失败！" + XMLHttpRequest.status);
                        }
                    });
                    return false;
                });
            });
        </script>
    </body>
</html>